﻿
Option Explicit On
'*******************************************************************
' Program: pkgVisio
' Author: Albert E Edlund
' Date:
'
' Purpose:
' Working with office object XML
'
'*******************************************************************


#Region " imports "

Imports System
Imports System.Object
Imports System.IO
Imports System.IO.TextReader
' need to reference windowsbase in .net
Imports System.IO.Packaging

' need for dbconnectionstringbuilder used in clsConnections
Imports System.Data.Common

Imports System.Windows
Imports System.Windows.Forms
Imports System.Text.StringBuilder

Imports Microsoft.VisualBasic

Imports System.Text
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.ObjectModel

Imports System.Xml
Imports System.Linq
Imports System.Linq.Enumerable
Imports System.Windows.Input

Imports System.Xml.Serialization
Imports System.Xml.Linq
Imports System.Xml.XPath

Imports ADODB
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.Sql


Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging



' visio v15 does not use a xName prefix which may put it into conflict with other open office apps
Imports <xmlns="http://schemas.microsoft.com/office/visio/2012/main">
Imports <xmlns:rs="urn:schemas-microsoft-com:rowset">

' generic namespace for office open xml, used in all of them
Imports <xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">

Imports pkgVisio.clsVisPackage


#End Region


'**********************************************************************************
'
'**********************************************************************************
'
Public Class clsCell

#Region " properties and declarations "

    'moved stcCell to clsStructures

#End Region


#Region " methods "


    '
    ' pass in an xelement, a search string for the cell name, and a search type
    ' return the xelement cell if it exists
    '
    Public Function existsCell _
        (ByVal elemObject As XElement, _
         ByVal strCellName As String, _
         Optional ByVal strType As String = "root") _
        As XElement

        Dim xelemReturn As XElement = Nothing
        Try

            Dim strSrch As String

            If LCase(strType) = "root" Or LCase(strType) = "all" Then
                strSrch = strType
            Else
                GoTo ExitFunction
            End If

            If elemObject Is Nothing Then GoTo ExitFunction

            Dim qryCells As System.Collections.Generic.IEnumerable(Of System.Xml.Linq.XElement)

            If strSrch = "all" Then
                qryCells = From cellSel In elemObject...<Cell>
                    Where LCase(cellSel.@N) = LCase(strCellName)
            Else
                qryCells = From cellSel In elemObject.<Cell>
                    Where LCase(cellSel.@N) = LCase(strCellName)
            End If

            Dim intCount As Integer = qryCells.Count
            If intCount > 0 Then
                xelemReturn = qryCells.First
            Else
                ' MsgBox("could not find cell")
            End If ' test that only one page was found


        Catch errXml As XmlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(errXml, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Catch err As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(err, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try
ExitFunction:
        existsCell = xelemReturn
    End Function


#End Region

    '
    '
    '
    Public Sub New()

    End Sub


End Class

